<template>
	<publicList :list="list" :addpageUrl="'/pages/monitor/information/information'" @detail="detail" :options="options"  @bindClick="bindClick" @savestate="savestate" :nullData="nullData"></publicList>
</template>
<script>
	import publicList from '@/components/publicList/index.vue'
	export default {
		components:{publicList},
		data () {
			return {
				pageIndex: 1,
				pageSize: 10,
				list: null,
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#EE2437' // 删除按钮背景  红的
					}
				}],
				page:1,
				deleteList:'',
				nullData: false,
			}
		},
		onLoad() {
			this.getlist({pageIndex:this.pageIndex,pageSize:this.pageSize})
		},
		onReachBottom() {
			if(this.nullData == true){
				return;
			}
			this.page = this.page + 1
			this.getlist({pageIndex:this.page,pageSize:this.pageSize})
		},
		methods:{
			getlist(data){
				this.$api.UserInfolist(data).then((res)=>{
					var data = res.data.result.list.map((a)=> {
						a.updateTime = a.updateTime;
						return a
					});
					if(this.deleteList == 1) {
						this.list = []
						this.list = data
						this.deleteList = ''
					}else {
						this.list = this.list ? this.list.concat(data) : data
					}
					if(this.list.length >= res.data.result.totalCount){
						this.nullData = true;
					}
				})
			},
			detail(e) {
				if(e.status == 1) {
					uni.navigateTo({
					  url:'/pages/monitor/information/information?id='+e.id
					})
				} else if(e.status == 2) {
					uni.navigateTo({
					  url:'/pages/monitor/information/toView?id='+e.id
					})
				}
			},
			bindClick(e) {
				const id = e.id;
				this.$api.UserinforDeleteId(id).then((res) => {
					if(res.data.returnCode == '200') {
						uni.showToast({
							title: '删除成功',
							icon: 'none'
						})
						this.page = 1
						this.deleteList = 1;
						this.nullData = false;
						this.getlist({pageIndex:this.pageIndex,pageSize:this.pageSize})
					}
				})
			},
			savestate(e) {
				e.status = 2
				if(e.geneticHistory == null) {
					e.geneticHistory = null
				}
				this.$api.userinforUpdate(e).then((res) => {
					if(res.data.returnCode =='200') {
						uni.showToast({
							title: '存档成功',
							icon: 'none'						
						})
						this.deleteList = 1;
						setTimeout(() => {
							this.getlist({pageIndex:this.pageIndex,pageSize:this.pageSize})
						},1000)
					}
				})
			}
		}
		
	}
</script>

